package edu.friday.controller;

import edu.friday.common.base.BaseController;
import edu.friday.common.result.RestResult;
import edu.friday.common.security.LoginUser;
import edu.friday.common.security.service.TokenService;
import edu.friday.model.SysMenu;
import edu.friday.model.vo.SysMenuVO;
import edu.friday.service.SysMenuService;
import edu.friday.utils.http.ServletUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/system/menu")
public class SysMenuController extends BaseController {
    @Autowired
    private SysMenuService menuService;

    //获取当前用户的信息
    @Autowired
    private TokenService tokenService;

    @GetMapping("/list")
    public RestResult list(SysMenuVO menu){
        //获取当前用户的信息
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());

        Long userId = loginUser.getUser().getUserId();

        List<SysMenu> menus = menuService.selectMenuList(menu,userId);
        return RestResult.success(menus);

    }

}
